#ifndef MMC_H
#define MMC_H

#include <string.h>

typedef unsigned char uint8_t;

enum R1_FLAGS {
    R1_IN_IDLE_STATE        = 1,
    R1_ERASE_RESET          = 2,
    R1_ILLEGAL_COMMAND      = 4,
    R1_SWITCH_ERROR         = 4,
    R1_COM_CRC_ERROR        = 8,
    R1_ERASE_SEQUENCE_ERROR = 16,
    R1_ADDRESS_MISALIGN     = 32,
    R1_ADDRESS_OUT_OF_RANGE = 64,
    R1_START_MASK           = 128,

    // this isn't in the MMC protocol 
    R1_RESPONSE_NOT_RECIEVED = 128
};

enum R2_FLAGS {
    R2_CARD_IS_LOCKED         = 1,
    R2_WP_ERASE_SKIP          = 2,
    R2_LOCK_UNLOCK_CMD_FAILED = 2,
    R2_EXECUTION_ERROR        = 4,
    R2_CARD_ERROR             = 8,
    R2_CARD_ECC_FAILED        = 16,
    R2_WP_VIOLATION           = 32,
    R2_ERASE_PARAM            = 64,
    R2_CSD_OVERWRITE          = 128
};

typedef struct {
    enum R1_FLAGS r1flags;
} R1;

typedef struct {
    enum R1_FLAGS r1flags;
    enum R2_FLAGS r2flags;
} R2;

typedef struct {
    enum R1_FLAGS r1flags;
    uint8_t ocr[4]; // should look into abstracting this (watch for padding!)
} R3;

int  mmc_init();
// void mmc_command(char cmd, unsigned long arg);
int  mmc_read_response(void *buf, size_t size);

#endif // MMC_H
